<template>
	<view class="all-main">
		<view class="main">
			<view class="phone">
				<view class="titles">
					<text>商户手机号</text>
				</view>
				<view class="inputs">
					<input type="number" v-model="merchant.custLogin" placeholder="请输入手机号" />
				</view>
			</view>
			<view class="msg">
				<text>将作为商户APP登录账号</text>
			</view>
			<view class="lists">
				<view class="items">
					<view class="lefts">
						<text>产品政策</text>
					</view>
					<view class="rights" @click="policyClick">
						<text>{{merchant.policy_name}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>主体类型</text>
					</view>
					<view class="rights" @click="typeClick">
						<text>{{merchant.mer_name}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
			</view>
			<view v-if="merchant.busType != ''" class="entry-type">
				<view class="lefts">
					<text>进件方式</text>
				</view>
				<view class="rights" @click="entryTypeClick">
					<text>{{merchant.entry_type_text}}</text>
					<u-icon name="arrow-right" size="15"></u-icon>
				</view>
			</view>
			<!-- 其他组织机构 -->
			<view v-if="merchant.busType == 5" class="lists">
				<view class="merchant-title">
					<text>商户信息</text>
				</view>
				<view class="items">
					<view class="lefts">
						<text>证书类型</text>
					</view>
					<view class="rights" @click="cretTypeShow = true">
						<text>{{merchant.certificate_type_text}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="certificate-one">
					<view class="certificate-images">
						<image id="img4" :src="image4" mode="" @click="imageClick(4)"></image>
					</view>
					<view class="certificate-title">
						<text>登记证书</text>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>商户名称</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.busName" placeholder="请与营业执照一致" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>证书编号</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.licenseno" placeholder="请与营业执照一致" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>证书有效期</text>
					</view>
					<view class="rights" @click="certificate_validity_showA = true">
						<text>{{merchant.certificate_validity}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>商户简称</text>
						<u-icon name="question-circle" color="#f2873a" size="19" @click="merchantSubNameClick"></u-icon>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.refName" placeholder="输入市+名称+主营" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>经营类目</text>
					</view>
					<view class="rights" @click="busCategoryClick">
						<text>{{merchant.bus_category_text}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>所在地区</text>
					</view>
					<view class="rights" @click="addressShow = true">
						<text>{{merchant.area}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>详细地址</text>
					</view>
					<view class="rights">
						<view class="inputs">
							<input type="text" v-model="merchant.custAddr" placeholder="请输入详细地址" />
						</view>
						<u-icon name="map" size="15" @click="mapClick"></u-icon>
					</view>
				</view>
			</view>
			<!-- 其他组织机构 -->
			<!-- 政府及事业单位 -->
			<view v-if="merchant.busType == 3" class="lists">
				<view class="merchant-title">
					<text>商户信息</text>
				</view>
				<view class="items">
					<view class="lefts">
						<text>证书类型</text>
					</view>
					<view class="rights" @click="cretTypeShow = true">
						<text>{{merchant.certificate_type_text}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="certificate-two">
					<view class="certificate-lefts">
						<view class="certificate-images">
							<image id="img2" :src="image2" mode="" @click="imageClick(2)"></image>
						</view>
						<view class="certificate-title">
							<text>登记证书</text>
						</view>
					</view>
					<view class="certificate-rights">
						<view class="certificate-images">
							<image id="img3" :src="image3" mode="" @click="imageClick(3)"></image>
						</view>
						<view class="certificate-title">
							<text>单位证明函</text>
							<text class="looks" @click="lookTmp">(查看模版)</text>
						</view>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>商户名称</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.busName" placeholder="请与营业执照一致" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>证书编号</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.licenseno" placeholder="请与营业执照一致" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>证书有效期</text>
					</view>
					<view class="rights" @click="certificate_validity_showA = true">
						<text>{{merchant.certificate_validity}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>商户简称</text>
						<u-icon name="question-circle" color="#f2873a" size="19" @click="merchantSubNameClick"></u-icon>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.refName" placeholder="输入市+名称+主营" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>经营类目</text>
					</view>
					<view class="rights" @click="busCategoryClick">
						<text>{{merchant.bus_category_text}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>所在地区</text>
					</view>
					<view class="rights" @click="addressShow = true">
						<text>{{merchant.area}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>详细地址</text>
					</view>
					<view class="rights">
						<view class="inputs">
							<input type="text" v-model="merchant.custAddr" placeholder="请输入详细地址" />
						</view>
						<u-icon name="map" size="15" @click="mapClick"></u-icon>
					</view>
				</view>
			</view>
			<!-- 政府及事业单位 -->
			<!-- 个体工商户/企业商户 -->
			<view v-if="merchant.busType == 1 || merchant.busType == 2" class="lists">
				<view class="merchant-title">
					<text>商户信息</text>
				</view>
				<view class="certificate-one">
					<view class="certificate-images">
						<image id="img1" :src="image1" mode="" @click="imageClick(1)"></image>
					</view>
					<view class="certificate-title">
						<text>营业执照</text>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>商户名称</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.busName" placeholder="请与营业执照一致" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>营业执照号</text>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.licenseno" placeholder="请与营业执照一致" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>营业执照有效期</text>
					</view>
					<view class="rights" @click="certificate_validity_showA = true">
						<text>{{merchant.certificate_validity}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>商户简称</text>
						<u-icon name="question-circle" color="#f2873a" size="19" @click="merchantSubNameClick"></u-icon>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.refName" placeholder="输入市+名称+主营" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>经营类目</text>
					</view>
					<view class="rights" @click="busCategoryClick">
						<text>{{merchant.bus_category_text}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>所在地区</text>
					</view>
					<view class="rights" @click="addressShow = true">
						<text>{{merchant.area}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>详细地址</text>
					</view>
					<view class="rights">
						<view class="inputs">
							<input type="text" v-model="merchant.custAddr" placeholder="请输入详细地址" />
						</view>
						<u-icon name="map" size="15" @click="mapClick"></u-icon>
					</view>
				</view>
			</view>
			<!-- 个体工商户 -->
			<!-- 小微商户 -->
			<view v-if="merchant.busType == 4" class="lists">
				<view class="merchant-title">
					<text>商户信息</text>
				</view>
				<view class="items">
					<view class="lefts">
						<text>商户名称</text>
						<u-icon name="question-circle" color="#f2873a" size="19" @click="merchantMsg"></u-icon>
					</view>
					<view class="rights">
						<input type="text" v-model="merchant.busName" placeholder="输入市+名称+主营" />
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>经营类目</text>
					</view>
					<view class="rights" @click="busCategoryClick">
						<text>{{merchant.bus_category_text}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>所在地区</text>
					</view>
					<view class="rights" @click="addressShow = true">
						<text>{{merchant.area}}</text>
						<u-icon name="arrow-right" size="15"></u-icon>
					</view>
				</view>
				<view class="items">
					<view class="lefts">
						<text>详细地址</text>
					</view>
					<view class="rights">
						<view class="inputs">
							<input type="text" v-model="merchant.custAddr" placeholder="请输入详细地址" />
						</view>
						<u-icon name="map" size="15" @click="mapClick"></u-icon>
					</view>
				</view>
			</view>
			<!-- 小微商户 -->
			<view class="occupy_position"></view>
			<view v-if="merchant.custId == '' || merchant.custId == null" class="bottom-btn">
				<view class="btn-left" @click="saveData(2)">
					<text>暂存</text>
				</view>
				<view class="btn-right" @click="saveData(1)">
					<text>下一步</text>
				</view>
			</view>
			<view v-else class="bottom-btn">
				<view class="btns" @click="saveData(1)">
					<text>下一步</text>
				</view>
			</view>
			<u-popup :show="typeShow" :round="10" mode="bottom" :closeable="true" @close="typeShow = false">
				<view class="type-main">
					<view class="type-title">
						<text>主体类型</text>
					</view>
					<view class="type-list">
						<view v-for="(item, index) in typeList" :key="index" class="type-item"
							@click="typeSelect(item)">
							<view class="type-item-left">
								<u-icon :name="'/static/icons/mcc_type_' + index + '.png'" size="40"></u-icon>
							</view>
							<view class="type-item-right">
								<view class="type-item-title">
									<text>{{item.title}}</text>
								</view>
								<view class="type-item-msg">
									<text>{{item.msg}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</u-popup>
			<u-picker :show="policyShow" :columns="policyList" keyName="label" :closeOnClickOverlay="true"
				@confirm="policyConfirm" @close="policyShow = false" @cancel="policyShow = false"></u-picker>
			<u-picker :show="cretTypeShow" :columns="cretTypeList" keyName="label" :closeOnClickOverlay="true"
				@confirm="cretTypeConfirm" @close="cretTypeShow = false" @cancel="cretTypeShow = false"></u-picker>
			<u-modal :show="merchantNameShow" :title="merchantInfo.title" :content='merchantInfo.msg'
				@confirm="merchantNameShow = false" :closeOnClickOverlay="true"
				@close="merchantNameShow = false"></u-modal>
			<address-picker :show="addressShow" closeOnClickOverlay @confirm='confirmAddress'
				@cancel='addressShow=false' @close='addressShow = false' :address-data="addressData" :indexs="indexs"
				:areaId="areaId" :type="type"></address-picker>
			<u-picker :show="entry_type_show" :columns="entry_type_list" keyName="label" :closeOnClickOverlay="true"
				@confirm="entryTypeConfirm" @close="entry_type_show = false"
				@cancel="entry_type_show = false"></u-picker>
			<u-datetime-picker :show="certificate_validity_showA" title="开始时间" v-model="merchant.busStartDate"
				:minDate="-788950800000" :maxDate="4260182400000" mode="date" :closeOnClickOverlay="true"
				@confirm='startDateConfirm' @close="certificate_validity_showA = false"
				@cancel="certificate_validity_showA = false"></u-datetime-picker>
			<u-datetime-picker :show="certificate_validity_showB" title="截止时间" v-model="merchant.busEndDate"
				:minDate="-788950800000" :maxDate="4260182400000" mode="date" :closeOnClickOverlay="true"
				@confirm='endDateConfirm' @close="certificate_validity_showB = false"
				@cancel="certificate_validity_showB = false"></u-datetime-picker>
			<u-popup :show="image_show" @close="image_show = false">
				<view class="images_box">
					<view class="image_box">
						<text class="" @click="_picture">拍照</text>
						<text class="" @click="_getFile">手机相册选择</text>
					</view>
					<text @click.stop="image_show = false">取消</text>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	var util = require('@/util/request.js');
	import {
		pathToBase64,
		base64ToPath
	} from '@/js_sdk/mmmm-image-tools/index.js'
	export default {
		data() {
			return {
				typeShow: false,
				typeList: [],
				policyShow: false,
				policyList: [],
				entry_type_show: false,
				entry_type_list: [],
				cretTypeList: [],
				cretTypeShow: false,
				certificate_validity_showA: false,
				certificate_validity_showB: false,
				image_show: false,
				area: '请选择',
				address: '请选择',
				image1: '/static/business_license.png',
				image2: '/static/business_license.png',
				image3: '/static/business_license.png',
				image4: '/static/business_license.png',
				merchantNameShow: false,
				merchantInfo: {
					title: '',
					msg: '',
				},
				merchant: {
					id: '',
					custId: '',
					saveType: 1,
					pageSize: 1,
					busName: '', // 商户名称
					refName: '', // 商户简称
					custLogin: '', // 商户手机号
					policy_id: '', // 产品政策ID
					policy_name: '请选择', // 产品政策名称
					entry_type: '', // 进件方式
					entry_type_text: '请选择', // 进件方式名称
					busType: '', // 主体类型
					mer_name: '请选择', // 主体类型名称
					cretType: '', // 证书类型
					certificate_type_text: '请选择', // 证书类型名称
					certificate_path: '', // 证书路径
					prove_path: '', // 证明路径
					licenseno: '', // 证书编号
					certificate_validity: '请选择', // 证书有效期
					busStartDate: '', // 证书有效期开始
					busEndDate: '', // 证书有效期截止
					mcccode: '', // 经营类目
					bus_category_text: '请选择', // 经营类目名称
					area_ids: '', // 地区ID
					provId: '', // 省
					cityId: '', // 市
					areaId: '', // 区/县
					area: '请选择', // 地区名称
					custAddr: '', // 详细地址
					timestamp: '', // 图片上传返回时间戳
					images: {
						busPhotoFront: '',
						filed4: ''
					}
				},
				addressShow: false,
				indexs: [0, 0, 0],
				areaId: [1, 110000, 110101],
				addressData: ['北京市', '北京市', '东城区'],
				type: 3, // 1-省，2-省市，3-省市区
				image_types: '',
				flag: '',
			}
		},
		onLoad(e) {
			if (e.id) {
				this.getMerchantEntry(e.id)
			}
			this.merchant.busStartDate = Number(new Date())
			this.merchant.busEndDate = Number(new Date())
		},
		onShow() {

		},
		mounted() {
			var that = this
			uni.$on('mer_mcc', function(data) {
				that.merchant.mcccode = data
			})
			uni.$on('mer_name', function(data) {
				that.merchant.bus_category_text = data
			})
			uni.$on('data_id', function(data) {
				that.getMerchantEntry(data)
			})
		},
		methods: {
			// 获取主体类型
			async getPrincipalType() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getPrincipalType',
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.typeList = res.data
					this.typeShow = true
				}
			},
			// 获取产品政策
			async getPolicyList() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getPolicyList',
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.policyList = [res.data]
					this.policyShow = true
				}
			},
			// 获取商户名称说明
			async getMerchantMsg() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getMerchantMsg',
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.merchantInfo = res.data
					this.merchantNameShow = true
				}
			},
			// 获取进件方式
			async getEntryType() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getEntryType',
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.entry_type_list = [res.data]
					this.entry_type_show = true
				}
			},
			// 获取商户进件信息
			async getMerchantEntry(data) {
				if (this.merchant.id != data) {
					uni.showLoading({
						title: '加载中'
					});
					const {
						data: res
					} = await this.$myHttp({
						url: 'v1/getMerchantEntry',
						data: {
							id: data
						}
					});
					uni.hideLoading()
					if (res.code == 200) {
						this.merchant = res.data
						if  (res.data.busType == 5) {
							if (res.data.images.busPhotoFront) {
								this.image4 = util.API_URL + res.data.images.busPhotoFront
							}
						} else if (res.data.busType == 3) {
							if (res.data.images.busPhotoFront) {
								this.image2 = util.API_URL + res.data.images.busPhotoFront
							}
							if (res.data.images.filed4) {
								this.image3 = util.API_URL + res.data.images.filed4
							}
						} else if (res.data.busType == 1 || res.data.busType == 2) {
							if (res.data.images.busPhotoFront) {
								this.image1 = util.API_URL + res.data.images.busPhotoFront
							}
						}
					}
				}
			},
			// 获取证书类型
			async getCretTypeList() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getCretTypeList',
					data: {
						type: this.merchant.busType
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.cretTypeList = [res.data]
				}
			},
			// 点击产品政策
			policyClick() {
				if (this.policyList.length <= 0) {
					this.getPolicyList()
				} else {
					this.policyShow = true
				}
			},
			// 点击商户类型
			typeClick() {
				if (this.merchant.policy_id == '') {
					uni.showToast({
						title: "请先选择产品政策",
						duration: 1000,
						icon: "none"
					});
					return false
				}
				if (this.typeList.length <= 0) {
					this.getPrincipalType()
				} else {
					this.typeShow = true
				}
			},
			// 选择商户主体类型
			typeSelect(item) {
				this.merchant.busType = item.id
				this.merchant.mer_name = item.title
				if (item.id == 1 || item.id == 2) {
					this.merchant.cretType = 5
				}
				this.typeShow = false
				this.cretTypeList = []
				this.getCretTypeList()
			},
			// 选择证书类型
			cretTypeConfirm(e) {
				this.merchant.cretType = e.value[0].id
				this.merchant.certificate_type_text = e.value[0].label
				this.cretTypeShow = false
			},
			// 选择产品政策
			policyConfirm(e) {
				this.merchant.policy_id = e.value[0].id
				this.merchant.policy_name = e.value[0].label
				this.policyShow = false
			},
			// 点击进件方式
			entryTypeClick() {
				if (this.entry_type_list.length <= 0) {
					this.getEntryType()
				} else {
					this.entry_type_show = true
				}
			},
			// 选择进件方式
			entryTypeConfirm(e) {
				this.merchant.entry_type = e.value[0].id
				this.merchant.entry_type_text = e.value[0].label
				this.entry_type_show = false
			},
			// 商户名称说明
			merchantMsg() {
				if (this.merchantInfo.title == '') {
					this.getMerchantMsg()
				} else {
					this.merchantNameShow = true
				}
			},
			// 点击商户简称说明
			merchantSubNameClick() {
				uni.navigateTo({
					url: '/pages/index/guotong/subname'
				})
			},
			// 单位证明函（查看模版）
			lookTmp() {
				uni.navigateTo({
					url: '/pages/index/guotong/filetemplate'
				})
			},
			// 点击经营类目
			busCategoryClick() {
				uni.navigateTo({
					url: '/pages/index/guotong/bus_category?type=' + this.merchant.busType
				})
			},
			// 选择地址
			confirmAddress(val) {
				this.merchant.area_ids = val.areaId
				this.areaId = val.areaId
				this.merchant.provId = val.areaId[0]
				this.merchant.cityId = val.areaId[1]
				this.merchant.areaId = val.areaId[2]
				this.indexs = val.indexs
				this.addressData = val.value
				this.merchant.area = val.value.join('')
				this.addressShow = false
			},
			// 地图选择
			mapClick() {
				uni.navigateTo({
					url: '/pages/index/guotong/map'
				})
			},
			// 证书有效时间 - 开始时间选择
			startDateConfirm(e) {
				this.certificate_validity_showA = false
				this.certificate_validity_showB = true
			},
			// 证书有效时间 - 截止时间选择
			endDateConfirm(e) {
				const timeFormat = uni.$u.timeFormat
				this.merchant.certificate_validity = timeFormat(this.merchant.busStartDate, 'yyyy-mm-dd') +
					' 至 ' + timeFormat(e.value, 'yyyy-mm-dd')
				this.certificate_validity_showB = false
			},
			// 文件上传 - 点击
			imageClick(type) {
				if (this.merchant.custLogin == '') {
					uni.showToast({
						title: '请先输入商户手机号',
						icon: 'none',
						duration: 3000
					})
					return false
				}
				if (type == 4 || type == 2) {
					if (this.merchant.cretType == '') {
						uni.showToast({
							title: '请先选择证书类型',
							icon: 'none',
							duration: 3000
						})
						return false
					}
				}
				if (type == 1 || type == 2 || type == 4) {
					this.flag = 12
				}
				if (type == 3) {
					this.flag = 9
				}
				this.image_types = type
				this.image_show = true
			},
			// 拍照
			_getFile() {
				let _this = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						pathToBase64(res.tempFilePaths[0])
							.then(base64 => {
								_this.uploadFile(base64)
								_this.image_show = false
							})
							.catch(error => {})
					}
				});
			},
			// 手机相册
			_picture() {
				let _this = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //从相机选择
					success: function(res) {
						pathToBase64(res.tempFilePaths[0])
							.then(base64 => {
								_this.uploadFile(base64)
								_this.image_show = false
							})
							.catch(error => {})
					}
				});
			},
			// 上传图片
			async uploadFile(base) {
				uni.showLoading({
					title: '上传中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'common/gtUploadFile',
					data: {
						file: base,
						type: this.image_types,
						flag: this.flag,
						timestamp: this.merchant.timestamp,
						custLogin: this.merchant.custLogin,
						custId: this.merchant.custId
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					this.merchant.timestamp = res.data.timestamp
					if (this.image_types == 1) {
						this.merchant.certificate_path = res.data.url
						this.image1 = base
					} else if (this.image_types == 2) {
						this.merchant.certificate_path = res.data.url
						this.image2 = base
					} else if (this.image_types == 3) {
						this.merchant.prove_path = res.data.url
						this.image3 = base
					} else if (this.image_types == 4) {
						this.merchant.certificate_path = res.data.url
						this.image4 = base
					} else {
						this.merchant.certificate_path = res.data.url
						this.image5 = base
					}
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000
					})
				}
			},
			// 保存数据
			saveData(type) {
				var _this = this
				var msg = ''
				this.merchant.saveType = type
				if (this.merchant.custLogin == '') {
					uni.showToast({
						title: '请输入商户手机号',
						icon: 'none',
						duration: 3000
					})
					return false
				}
				if (this.merchant.policy_id == '') {
					uni.showToast({
						title: '请选择产品政策',
						icon: 'none',
						duration: 3000
					})
					return false
				}
				if (this.merchant.busType == '') {
					uni.showToast({
						title: '请选择主体类型',
						icon: 'none',
						duration: 3000
					})
					return false
				}
				if (this.merchant.busType == 1 || this.merchant.busType == 2) {
					if (this.merchant.certificate_path == '') {
						uni.showToast({
							title: '请上传营业执照',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.busName == '') {
						uni.showToast({
							title: '请输入商户名称',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.licenseno == '') {
						uni.showToast({
							title: '请输入营业执照号',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.certificate_validity == '请选择') {
						uni.showToast({
							title: '请选择营业执照有效期',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.refName == '') {
						uni.showToast({
							title: '请输入商户简称',
							icon: 'none',
							duration: 3000
						})
						return false
					}
				} else if (this.merchant.busType == 3) {
					if (this.merchant.cretType == '') {
						uni.showToast({
							title: '请选择证书类型',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.certificate_path == '') {
						uni.showToast({
							title: '请上传登记证书',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.prove_path == '') {
						uni.showToast({
							title: '请上传单位证明函',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.busName == '') {
						uni.showToast({
							title: '请输入商户名称',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.licenseno == '') {
						uni.showToast({
							title: '请输入证书编号',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.certificate_validity == '') {
						uni.showToast({
							title: '请选择证书有效期',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.refName == '') {
						uni.showToast({
							title: '请输入商户简称',
							icon: 'none',
							duration: 3000
						})
						return false
					}
				} else if (this.merchant.busType == 4) {
					if (this.merchant.busName == '') {
						uni.showToast({
							title: '请输入商户名称',
							icon: 'none',
							duration: 3000
						})
						return false
					}
				} else if (this.merchant.busType == 5) {
					if (this.merchant.cretType == '') {
						uni.showToast({
							title: '请选择证书类型',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.certificate_path == '') {
						uni.showToast({
							title: '请上传登记证书',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.busName == '') {
						uni.showToast({
							title: '请输入商户名称',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.licenseno == '') {
						uni.showToast({
							title: '请输入证书编号',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.certificate_validity == '') {
						uni.showToast({
							title: '请选择证书有效期',
							icon: 'none',
							duration: 3000
						})
						return false
					}
					if (this.merchant.refName == '') {
						uni.showToast({
							title: '请输入商户简称',
							icon: 'none',
							duration: 3000
						})
						return false
					}
				}
				if (this.merchant.mcccode == '') {
					uni.showToast({
						title: '请选择经营类目',
						icon: 'none',
						duration: 3000
					})
					return false
				}
				if (this.merchant.area == '请选择') {
					uni.showToast({
						title: '请选择所在地区',
						icon: 'none',
						duration: 3000
					})
					return false
				}
				if (this.merchant.custAddr == '') {
					uni.showToast({
						title: '请输入详细地址',
						icon: 'none',
						duration: 3000
					})
					return false
				}
				if (type == 2) {
					msg = '是否要选择暂存当前信息？'
				} else {
					msg = '是否确认当前信息，进行下一步？'
				}
				uni.showModal({
					content: msg,
					success: (res) => {
						if (res.confirm) {
							_this.saveDataFun()
						}
					}
				})
			},
			// 提交数据
			async saveDataFun() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/merchantEntry',
					data: this.merchant,
				});
				uni.hideLoading()
				if (res.code == 200) {
					if (this.merchant.saveType == 2) {
						uni.navigateBack({})
					} else {
						uni.navigateTo({
							url: '/pages/index/guotong/settlement?id=' + res.data.id
						})
					}
				}
			},
		}
	}
</script>

<style lang="scss">
	.all-main {
		.main {
			.phone {
				margin: 20rpx 20rpx 0 20rpx;
				display: flex;
				justify-content: space-between;
				background-color: #ffffff;
				padding: 30rpx;
				border-radius: 10rpx;

				.inputs {
					input {
						text-align: right;
					}
				}
			}

			.entry-type {
				margin: 20rpx 20rpx 0 20rpx;
				display: flex;
				justify-content: space-between;
				background-color: #ffffff;
				padding: 30rpx;
				border-radius: 10rpx;
				font-size: 28rpx;

				.lefts {
					width: 30%;
				}

				.rights {
					width: 70%;
					display: flex;
					justify-content: flex-end;
					align-items: center;

					text {
						padding-right: 10rpx;
						color: #909399;
					}
				}
			}

			.msg {
				margin: 20rpx 20rpx 0 20rpx;
				padding-left: 30rpx;
				font-size: 24rpx;
				color: #909399;
			}

			.lists {
				margin: 20rpx;
				padding: 0 30rpx;
				background-color: #ffffff;
				border-radius: 10rpx;

				.merchant-title {
					padding: 30rpx 0;
					font-size: 32rpx;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;
				}

				.certificate-one {
					padding: 20rpx 0;

					.certificate-images {
						text-align: center;
						position: relative;

						image {
							padding: 20rpx 30rpx;
							border: 2px solid #f4f4f5;
							border-radius: 16rpx;
							width: 95px;
							height: 60px;
						}
					}

					.certificate-title {
						color: #909399;
						text-align: center;
						font-size: 28rpx;
					}
				}

				.certificate-two {
					display: flex;
					justify-content: space-between;

					.certificate-lefts {
						width: 50%;
						padding: 20rpx 0;
					}

					.certificate-rights {
						width: 50%;
						padding: 20rpx 0;
					}

					.certificate-images {
						text-align: center;
						position: relative;

						image {
							padding: 20rpx 30rpx;
							border: 2px solid #f4f4f5;
							border-radius: 16rpx;
							width: 95px;
							height: 60px;
						}
					}

					.certificate-title {
						color: #909399;
						text-align: center;
						font-size: 28rpx;
						
						.looks {
							color: #f2873a;
						}
					}
				}

				.items {
					padding: 30rpx 0;
					border-bottom: 1px solid #f4f4f5;
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 28rpx;

					.lefts {
						width: 30%;
						display: flex;
						align-items: center;

						text {
							margin-right: 10rpx;
						}
					}

					.rights {
						width: 70%;
						display: flex;
						justify-content: flex-end;
						align-items: center;

						input {
							text-align: right;
							font-size: 28rpx;
						}

						.inputs {
							margin-right: 10rpx;
						}

						text {
							padding-right: 10rpx;
							color: #909399;
						}
					}
				}
			}

			.type-main {
				.type-title {
					text-align: center;
					padding: 20rpx;
					font-size: 34rpx;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;
				}

				.type-list {
					padding: 0 20rpx;

					.type-item {
						padding: 20rpx 0;
						display: flex;
						align-items: center;
						border-bottom: 1px solid #f4f4f5;

						.type-item-right {
							margin-left: 20rpx;

							.type-item-title {
								font-weight: bold;
							}

							.type-item-msg {
								font-size: 24rpx;
								color: #909399;
							}
						}
					}
				}
			}

			.occupy_position {
				height: 140rpx;
			}

			.bottom-btn {
				position: fixed;
				left: 0;
				right: 0;
				bottom: 0;
				padding: 30rpx;
				background-color: #ffffff;
				display: flex;
				justify-content: space-between;

				.btn-left {
					width: 48%;
					height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: #f8ece3;
					color: #f2873a;
					border-radius: 14rpx;
				}

				.btn-right {
					width: 48%;
					height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: #f2873a;
					color: #ffffff;
					border-radius: 14rpx;
				}
				
				.btns {
					width: 100%;
					height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: #f2873a;
					color: #ffffff;
					border-radius: 14rpx;
				}
			}

			.images_box {
				box-sizing: border-box;

				.phone {
					margin-bottom: 20rpx;
					border-bottom: #eee 1px solid;
					padding: 30rpx;
				}

				.image_box {
					margin-bottom: 30rpx;

					text {
						border-bottom: #eee solid 1px;
						padding: 20rpx 0;
						margin: 0;
					}
				}

				text {
					font-size: 32rpx;
					color: #1296db;
					text-align: center;
					display: block;
					margin-bottom: 30rpx;
					transition: all 0.5s;
				}

				text:active {
					background-color: #ebebeb;
				}
			}
		}
	}
</style>